<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.lmpop.trade.shopcart.*"%>
<%@page import="com.lmpop.trade.ts_categoryattr.*"%>
<%@page import="com.lmpop.frame.util.Config"%>
<%@page import="com.lmpop.createIndex.search.*"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="com.lmpop.trade.ti_gift.Ti_giftInfo"%>
<%@page import="com.lmpop.trade.ti_discountpolicy.Ti_discountpolicyInfo"%>
<%
	request.setCharacterEncoding("UTF-8");
	DecimalFormat df = new DecimalFormat("0.0");

	String info_state = "e";
	Map comMap = new Hashtable();
	comMap.put("info_state", info_state);
	AttachIndexFiles attachIndex = new AttachIndexFiles();
	GoodsIndexFiles goodsIndex = new GoodsIndexFiles();
	CompanyIndexFiles comIndex = new CompanyIndexFiles();
	CategoryattrIndexFiles attrIndex = new CategoryattrIndexFiles();
	WholesaleIndexFiles wholesaleIndex = new WholesaleIndexFiles();
	List goodsList = goodsIndex.getGoodsInfo(comMap);

	Config configa = new Config();
	configa.init();
	String goodsrootpath = configa.getString("goods_article_path");
	String custrootpath = configa.getString("company_shop_path");
	String noimg_path = "/program/images/cpwu.gif";

	Hashtable<String, Hashtable<String, Goods>> cartMap = null;
	CartServices shopcart = null;
	int listsize = 0;
	if (session.getAttribute("shoppingCart") != null) {
		shopcart = (CartServices) session.getAttribute("shoppingCart");
		cartMap = shopcart.getCartMap();
	}
	if (cartMap != null && cartMap.size() > 0) {
		listsize = cartMap.size();
	}

	float totalPrice = 0;
	float offerPrice = 0;
	int totalGoodsCount = 0;
	int totalIntegralNum = 0;
	String giftInfos = "";
	String discount_ids = "";
	String ordergift = "";
	int offer_type = 0;
	int session_custlevel = 0;
	if (session.getAttribute("member_level") != null) {
		session_custlevel = Integer.parseInt(session.getAttribute("member_level").toString().trim());
	}
	if (shopcart != null) {
		giftInfos = shopcart.getAllItemsGifts();
		totalPrice = shopcart.getAllItemsPrice();
		ordergift = shopcart.getGift_ids();
		offer_type = shopcart.getOffer_type();
		offerPrice = shopcart.getAllItemsOfferPrice(session_custlevel);
		totalGoodsCount = shopcart.getAllItemsCount();
		totalIntegralNum = shopcart.getAllItemsIntegralNum();
		discount_ids = shopcart.getAllItemsDiscountids();
	}

	Ti_giftInfo ti_giftInfo = new Ti_giftInfo();
	StringBuffer discountids = new StringBuffer();

	Ti_discountpolicyInfo discoutpolicyInfo = new Ti_discountpolicyInfo();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>购物车</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<LINK href="/templets/html/shop/css/mycart.css" type=text/css	rel=stylesheet>
<link href="/templets/html/shop/css/style.css" rel="stylesheet" type="text/css" />
<LINK href="/templets/html/shop/css/tbsp.css" rel=stylesheet>
<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/templets/html/shop/js/ShopCart.js"></script>
<script type="text/javascript" src="/js/thickbox/thickbox.js"></script>
<link href="/templets/html/shop/css/Home.css" rel="stylesheet" />
<SCRIPT src="/templets/html/shop/js/taobao.js"></SCRIPT>
<SCRIPT src="/templets/html/shop/js/nav_style_num.js"></SCRIPT>
<link rel="stylesheet" href="/js/thickbox/thickbox.css"	type="text/css" media="screen" />
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ts_areaInfo.js'></script>
<script type='text/javascript' src='/dwr/engine.js'></script>
<script type='text/javascript' src='/dwr/util.js'></script>
<script type='text/javascript' src='/dwr/interface/Ti_subscribeInfo.js'></script>
<script type='text/javascript' src='/templets/html/shop/js/_shop.js'></script>
</HEAD>
<BODY>
<script> 
  document.write("<s" + "cript type='text/javascript' src='/templets/html/shop/top.jsp?" + Math.random() + "'></scr" + "ipt>");
  TB.Header.init();  
</script> 

<!-- end vmcommon x -->

<div class="content0">
  <div class="chengxu">
    <div class="chengxu_m">
      <ul>
        <li class="txt_li">登录/注册<small>login/regist</small><img align="absmiddle" src="/templets/html/shop/images/jiantou_l.gif" /></li>
        <li class="tex_current">我的购物车<small>shopping cart</small><img align="absmiddle" src="/templets/html/shop/images/jiantou_r.gif" /></li>
        <li class="txt_li">填写订单信息<small>order information</small><img align="absmiddle" src="/templets/html/shop/images/jiantou.gif" /></li>
        <li class="txt_li">提交订单,付款<small>submit/pay</small><img align="absmiddle"src="/templets/html/shop/images/jiantou.gif" /></li>
        <li class="txt_li">等待收货<small>wait for delivery</small></li>
      </ul>
    </div>
  </div>
  <DIV class=grid-c id=content>
    <DIV class=status-bar id=status-bar data-limit="45" data-total="50">
      <DIV class=hd> </DIV>
      <DIV class=bd>
        <DIV class="kd-popup pop-back J_StatusContent hidden"> <I class=top></I> </DIV>
      </DIV>
    </DIV>
    <DIV id=cart>
      <DIV class=choose id=J_Choose>
        <div class="chooseall"> </div>
        <DIV class=total-fee>
          <DIV class="btn-small-un-go box-shadow J_MakePoint">
            <input class="delete" name="" type="submit"
						value="批量删除" onclick="delIndexInfo();">
            <%
					if(shopcart!=null&&shopcart.getAllItemsCount()>0){%>
            <input class="jiesuan" name="" type="submit" onclick="javascript:window.location.href='/templets/html/shop/jsp/confirm_order_address.jsp#hasaddress'"  value="结算">
            <%} %>
            </SPAN> </DIV>
          <SPAN class=total-fee-info>商品总价(不含运费)： <EM class=total2><span
					name="totalPrice" class="totalPrice">￥<%=df.format(totalPrice)%>元</span> </EM> </SPAN> </DIV>
      </DIV>
      <table width="100%" class="tablecart"> 
        <%
			if (cartMap != null && cartMap.size() > 0) {
				Set cartSet = cartMap.entrySet();
				Iterator cartIterator = cartSet.iterator();
				int i = 0;
		%>
        <tr>
          <th height="30" align="center" width="120"> <input type="checkbox" name="selectAllItems" id="selectAllItems"
					onclick="selectAllItems();">
            <strong>全选</strong> </th>
          <th width="300"> <strong>商品名称</strong> </th>
          <th width="200"> <strong>商品属性</strong> </th>
          <th width="150" > <strong>单价</strong> </th>
          <th width="100"> <strong>优惠价</strong> </th>
          <th width="100"> <strong>打折率</strong> </th>
          <th width="100"> <strong>数量</strong> </th>
          <th width="150"> <strong>小计</strong> </th>
          <th width="100"> <strong>购物类型</strong> </th>
          <th width="100"> <strong>操作</strong> </th>
          <input type="hidden" name="listsize" id="listsize"
				value="<%=listsize%>" />
        </tr>
        <%
			while (cartIterator.hasNext()) 
			{
				++i;
				Map.Entry entry = (Map.Entry) cartIterator.next();
				String cust_id = entry.getKey().toString();
				Hashtable<String, Goods> goodsMap = cartMap.get(cust_id);
				Map companyMap = comIndex.getCustNameById(cust_id);
				String sc_cust_name = "", sc_shop_name = "";
				if (companyMap.get("cust_name") != null)	sc_cust_name = companyMap.get("cust_name").toString();
				if (companyMap.get("cust_name") != null)	sc_shop_name = companyMap.get("cust_name").toString();
	
				Set goodsSet = goodsMap.entrySet();
				Iterator goodsIterator = goodsSet.iterator();
				int listsizei = goodsMap.size();
				String custUrl = custrootpath + cust_id + "/index.html";
%>
   <%
			int j = 0;
			List list = null;
			Map temp = null;
			giftInfos = "";
			while (goodsIterator.hasNext()) 
			{
				++j;
				Map.Entry goodsentry = (Map.Entry) goodsIterator.next();
				String goods_random_id = goodsentry.getKey().toString();
				String goods_id = goods_random_id.split("\\/")[0];
				Goods goodsInstance = goodsMap.get(goods_random_id);

				String goods_name = "",all_goods_name="";
				String goods_props = "";
				String goods_cust_id = "";
				String type = "";
				String type_id = "";
				float shop_price = 0;
				float vip_price = 0;
				int buy_num = 0;
				int goods_IntegralNum = 0;
				float goods_subtotal = 0;
				String attr_str = "";
				String in_date = "";
				int goods_stock = 0;
				int goods_singel_IntegralNum = 0;
				float goods_singel_price = 0f;
				String gift_id = "";
				String discount_id = "";
				String gift_name = "";
				String gift_names = "";
				float discount = 10;

				//out.println(goods_id);
				Map ginfoMap = goodsIndex.getOneGoods(goods_id,"_allgoods");
				if (ginfoMap.get("goods_name") != null && !ginfoMap.get("goods_name").toString().equals(""))
				{
					goods_name = ginfoMap.get("goods_name").toString();					 
				}	
				
				if (ginfoMap.get("in_date") != null	&& !ginfoMap.get("in_date").toString().equals(""))	in_date = ginfoMap.get("in_date").toString();
				if (ginfoMap.get("send_inter") != null && !ginfoMap.get("send_inter").toString().equals("")) goods_singel_IntegralNum = Integer.valueOf(ginfoMap.get("send_inter").toString());
				if (ginfoMap.get("sale_price") != null && !ginfoMap.get("sale_price").toString().equals("")) goods_singel_price = Float.valueOf(ginfoMap.get("sale_price").toString());
				if (ginfoMap.get("stock_num") != null && !ginfoMap.get("stock_num").toString().equals(""))	goods_stock = Integer.valueOf(ginfoMap.get("stock_num").toString());
				if (ginfoMap.get("discount_id") != null	&& !ginfoMap.get("discount_id").toString().equals("")) discount_id = ginfoMap.get("discount_id").toString();
				if (ginfoMap.get("cust_id") != null	&& !ginfoMap.get("cust_id").toString().equals(""))	goods_cust_id = ginfoMap.get("cust_id").toString();
				if (in_date.length() >= 8) 
				{
					String yeard = in_date.substring(0, 4);
					String monthd = in_date.substring(4, 6);
					String dayd = in_date.substring(6, 8);
					in_date = yeard + "-" + monthd + "-" + dayd;
				}

				goods_subtotal = goodsInstance.getTotalShopPrice();

				goods_IntegralNum = goodsInstance.getTotalIntegralNum();
				float offer_price = 0;
				if (goodsInstance != null) 
				{
					goods_props = goodsInstance.getGoods_props();
					shop_price = goodsInstance.getShop_price();
					vip_price = goodsInstance.getVip_price();
					buy_num = goodsInstance.getBuy_num();
					type = goodsInstance.getType();
					type_id = goodsInstance.getType_id();
					attr_str = attrIndex.getCatAttrFromStr(goods_props);
					offer_price = goodsInstance.getOffer_price();
					discount = (offer_price / shop_price) * 10;
					discount_id = goodsInstance.getDiscount_id();
					//取得礼品名称
					List dlist = discoutpolicyInfo.getDiscountByPK(discount_id);
					if (dlist.size() > 0 && dlist != null) 
					{
						Map mmap = (Map) dlist.get(0);
						if (mmap.get("gift_ids") != null) 
						{						
							List tlist = ti_giftInfo.getListByPk(mmap.get("gift_ids").toString());
							if (tlist != null && tlist.size() > 0) 
							{
								Map tmap = (Map) tlist.get(0);
								if (tmap.get("gift_name") != null)	gift_name = tmap.get("gift_name").toString();
							}
						}
					}
					if (gift_name == "" || gift_name == null)	gift_name = "无";
					gift_names = buy_num + "个" + gift_name;
					if (gift_name != "无")	giftInfos = giftInfos + gift_names + ";";					
				}
				String buy_type = "";
				if (type.equals("0")) buy_type = "普通购物";
				 
				String img_path = attachIndex.getFilepathById(goods_id);

				if (img_path.equals("")) img_path = "/program/admin/images/cpwu.gif";			

		  	String goodsUrl="";
				 
				goodsUrl=goodsrootpath+in_date+"/"+goods_id+".html";
				 
				 
%>
        <tr class="uncod xcard selected" id="goods_<%=goods_random_id%>" name="goods_<%=goods_random_id%>">
          <input type="hidden" name="listsize<%=i%>" id="listsize<%=i%>" value="<%=listsizei%>">
          <td width="30"><INPUT class=J_CheckBoxItem type=checkbox	name="<%=i%>checkone<%=j%>" id="<%=i%>checkone<%=j%>"	value="<%=goods_random_id%>" onclick="selectSingle();"></td>
          	
          <td width="300">
          	<a href="<%=goodsUrl%>" target="_blank"><img src="<%=img_path%>" border="0" style="float:left; width:46px; height:49px; margin-right:8px" align="absmiddle" /></a>
            <DIV class=props> <SPAN class=xcard-icon></SPAN> <SPAN><a target="_blank" href="<%=goodsUrl%>" alt="<%=goods_name%>"><%=goods_name%></a> </SPAN>
              <input name="goods_attr" id="goods_attr" type="hidden" value="<%=goods_props%>" />
              <input type="hidden" name="goodsIntegral_<%=goods_random_id%>" id="goodsIntegral_<%=goods_random_id%>"	value="<%=goods_singel_IntegralNum%>">
            </DIV>
          </td>
          
          <td>
						<a href="ajaxShowCatAtrr.jsp?cust_id=<%=cust_id%>&goods_id=<%=goods_random_id%>&goods_props=<%=goods_props%>&TB_iframe=true&height=300&width=500&KeepThis=true" class="thickbox"> 
					  <span	id="goods_attr_id_<%=goods_random_id%>"	name="goods_attr_id_<%=goods_random_id%>"><%=attr_str%></span> </a>
			    </td>
		
          <td>￥<span name="shop_price_<%=goods_random_id%>"	id="shop_price_<%=goods_random_id%>"><%=df.format(shop_price)%> </span></td>
          <td >￥<span name="offer_price_<%=goods_random_id%>"	id="offer_price_<%=goods_random_id%>"><%=df.format(offer_price)%> </span></td>
          <td><span name="discount_<%=goods_random_id%>" id="discount_<%=goods_random_id%>"><%=df.format(discount)%> </span></td>           
          <td><input class="input_pay" type="text" name="buy_num_<%=goods_random_id%>" id="buy_num_<%=goods_random_id%>" value="<%=buy_num%>" style="width: 40px;" maxlength="3" onkeyup='javascript:if((!/^[1-9][0-9]*$/.test(this.value))||(checkGoodsStock("<%=goods_id%>") > <%=goods_stock%>)){this.value="1";ShopCartOperating("<%=cust_id%>","<%=goods_random_id%>","2");}else{ShopCartOperating("<%=cust_id%>","<%=goods_random_id%>","2");}' /></td>

          <td>￥<%=df.format(goods_subtotal)%></td>
          <td><%=buy_type%></td>
          <td ><a href="#"	onclick="ShopCartOperating('<%=cust_id%>','<%=goods_random_id%>','3');">删除</a></td>
        </tr>       
        <div class="price">
        <%
		}
			}
	%>
        </table><p><SPAN class=total-fee-info>商品总价(不含运费)： 
        	<EM class=total2><span name="totalPrice" class="totalPrice">￥<%=df.format(totalPrice)%>元</span> </EM> </SPAN></p>
 					<p><SPAN class=total-fee-info>优惠价： <EM class=total2><span	name="offerPrice" class="totalPrice">￥<%=df.format(offerPrice)%>元</span> </EM> </SPAN></p>

         <%
						String giftInfosView = "";
						if (giftInfos != null && !giftInfos.equals("")) {
							giftInfosView = giftInfos.substring(0,
									giftInfos.length() - 1);
						}
				%>           
        <DIV class=msg></DIV>
        		<input type="hidden" name="discount_ids" id="discount_ids"	value="<%=discount_ids%>" />
            <input type="hidden" name="gift_ids" id="gift_ids"	value="<%=giftInfos%>" />
            <input type="hidden" name="offer_type" id="offer_type"	value="<%=offer_type%>" />
            <input type="hidden" name="ordergiftid" id="ordergiftid" value="<%=ordergift%>" />
            <DIV class="msg floatleft mg-left" style="DISPLAY: none"></DIV>
            <%				
						if(shopcart!=null&&shopcart.getAllItemsCount()>0)
						{
						%>
	            <BUTTON class="jiesuan_b"	onclick="javascript:window.location.href='/templets/html/shop/jsp/confirm_order_address.jsp#hasaddress'"> 结算 </BUTTON>
            <%
            }
				 		%>       
      <%
	} else {
%>
     </div>
      <TABLE id=J_CartEnable cellSpacing=0 cellPadding=0>
        <tr>
          <td><div class="gwc_k" style="width: 600px;"> <span><img src="/templets/html/shop/images/gwc_07.gif" align="absmiddle" /> </span> <span>您的购物车是空的，赶快行动吧！您可以：</span> <span>马上去 <A class=J_MakePoint href="/">挑选宝贝</A> </span>
              <div class="clear"></div>
            </div></td>
        </tr>
      </TABLE>
      <%
	}
%>
      <div name="hiddenData" id="hiddenData" style="display: none"> </div>
      <div name="hiddenAttrData" id="hiddenAttrData" style="display: none"> </div>
    </DIV>
    <DIV class=hidden id=empty> </DIV>
    <DIV id=interested>
      <H3> 您可能感兴趣的宝贝… </H3>
      <DIV class=con id=J_Auctions>
        <UL class=tabs>
        </UL>
        <DIV class="pannel J_Panel">
          <div class="divc_a divc_acon">
            <%
					int len = 5;
					if (goodsList != null && goodsList.size() > 0) {
						len = (len > goodsList.size()) ? goodsList.size() : len;
						Hashtable nMap = new Hashtable();
						for (int i = 0; i < len; i++) {
							nMap = (Hashtable) goodsList.get(i);
							String goods_name = "", sale_price = "", goods_id = "", infoUrl = "", in_date = "", file_path = "";
							if (nMap.get("goods_name") != null) {
								goods_name = nMap.get("goods_name").toString();
								if(goods_name.length()>15)
								goods_name=goods_name.substring(0,15);

							}
							if (nMap.get("sale_price") != null) {
								sale_price = nMap.get("sale_price").toString();
							}
							if (nMap.get("goods_id") != null) {
								goods_id = nMap.get("goods_id").toString();
							}
							file_path = attachIndex.getFilepathById(goods_id);
							if (file_path.equals(""))
								file_path = noimg_path;
							if (nMap.get("in_date") != null) {
								in_date = nMap.get("in_date").toString();
							}
							if (in_date.length() >= 8) {
								String yeard = in_date.substring(0, 4);
								String monthd = in_date.substring(4, 6);
								String dayd = in_date.substring(6, 8);
								in_date = yeard + "-" + monthd + "-" + dayd;
							}
							infoUrl = goodsrootpath + in_date + "/" + goods_id
									+ ".html";
				%>
            <dl>
              <dt> <a href="<%=infoUrl%>"><img src="<%=file_path%>"
							width="170" height="135"> </a> </dt>
              <dd> <a href="<%=infoUrl%>"><%=goods_name%></a> </dd>
              <dd> <a href="<%=infoUrl%>">￥<%=sale_price%>元</a> </dd>
            </dl>
            <%
				}
				}
			%>
          </div>
        </DIV>
      </DIV>
    </DIV>
  </DIV>
</DIV>
</div>
<!-- from vmcommon -->
</div>
</div>
<!--footer begin-->
<jsp:include page="/templets/html/shop/footer.jsp"/>
<!--footer over-->
</BODY>
</html>
